﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using HtmlAgilityPack;
using WebArchiveCopier.IO;

namespace WebArchiveCopier
{
	public class WebPage
	{
		private HtmlDocument document = null;
		private string address;
		private IDataManager dataManager;

		public WebPage(string address, IDataManager dataManager)
		{
			this.address = address;
			this.dataManager = dataManager;
		}

		protected IDataManager DataManager
		{
			get
			{
				return dataManager;
			}
		}

		protected HtmlDocument Document
		{
			get
			{
				if (document == null)
				{
					document = new HtmlDocument();
					byte[] data = dataManager.GetData(address);
					if (data != null)
					{
						var content = System.Text.Encoding.UTF8.GetString(data);
						document.LoadHtml(content);
					}
				}
				return document;
			}
		}

		public string Address
		{
			get
			{
				return address;
			}
		}
	}
}
